import logging
import os
from datetime import datetime


def setup_logger():
    """配置日志"""
    # 创建logs目录
    log_dir = "logs"
    if not os.path.exists(log_dir):
        os.makedirs(log_dir)

    # 生成日志文件名
    log_file = os.path.join(
        log_dir, f"data_shadow_{datetime.now().strftime('%Y%m%d_%H%M%S')}.log"
    )

    # 配置日志格式
    logging.basicConfig(
        level=logging.INFO,
        format="%(asctime)s [%(levelname)s] %(message)s",
        handlers=[
            logging.FileHandler(log_file, encoding="utf-8"),
            logging.StreamHandler(),
        ],
    )

    return logging.getLogger(__name__)


# 创建全局logger实例
logger = setup_logger()
